package com.wenwei.activity;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.wenwei.adapter.LookSuAdapter;
import com.wenwei.bean.LookSuBean;
import com.wenwei.bean.OrderInfoBean;
import com.wenwei.net.ApiManager;
import com.wenwei.net.BaseSubscriber;
import com.wenwei.parking.BaseActivity;
import com.wenwei.parking.R;
import com.wenwei.utils.RogerDateUtils;
import com.wenwei.view.GridLayoutManager;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by nidalee on 2017/10/16.
 */

public class LoookSuActivity extends BaseActivity {

    @Bind(R.id.base_title)
    TextView baseTitle;
    @Bind(R.id.record_address)
    TextView recordAddress;
    @Bind(R.id.record_time)
    TextView recordTime;
    @Bind(R.id.record_parking_time)
    TextView recordParkingTime;
    @Bind(R.id.input_msg_et)
    TextView inputMsgEt;
    @Bind(R.id.recycler)
    RecyclerView recycler;
    @Bind(R.id.price)
    TextView priceTv;
    @Bind(R.id.commit_btn)
    TextView commintBtn;

    private LookSuAdapter mAdapter;

    @Override
    public int setLayoutResourceId() {
        return R.layout.activity_pay_success_suu;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void initView() {
        super.initView();
        baseTitle.setText("申诉");
        commintBtn.setVisibility(View.GONE);

        recycler.setLayoutManager(new GridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL));
        recycler.setNestedScrollingEnabled(false);
        mAdapter = new LookSuAdapter();
        recycler.setAdapter(mAdapter);
    }


    @Override
    protected void initData() {
        super.initData();
        getOrderInfo();
        getAllegeByOrderId();
    }

    private BaseSubscriber<OrderInfoBean> infoSb;

    private void getOrderInfo() {
        infoSb = new BaseSubscriber<OrderInfoBean>(mContext) {
            @Override
            public void onSuccess(OrderInfoBean orderInfoBean) {
                initMsg(orderInfoBean);
            }
        };
        ApiManager.getInstance().getOrderInfo(infoSb, getIntent().getIntExtra("orderId", 0));
    }

    private BaseSubscriber<LookSuBean> suSb;

    private void getAllegeByOrderId() {
        suSb = new BaseSubscriber<LookSuBean>(mContext) {
            @Override
            public void onSuccess(LookSuBean lookSuBean) {
                inputMsgEt.setText(lookSuBean.getContent());
                mAdapter.setmList(lookSuBean.getImgList());
                mAdapter.notifyDataSetChanged();
            }
        };
        ApiManager.getInstance().getAllegeByOrderId(suSb, getIntent().getIntExtra("orderId", 0));
    }

    private void initMsg(OrderInfoBean infoBean) {
        recordAddress.setText(infoBean.getParkAddr());
        recordTime.setText(RogerDateUtils.getDateToHis(infoBean.getCreatedTime()));
        recordParkingTime.setText(infoBean.getParkLength() + "小时");
        priceTv.setText("¥" + infoBean.getPayTotal());
    }

    @OnClick(R.id.base_back)
    public void onViewClicked() {
        finish();
    }


}
